package com.joe.codemother.parser;

import com.joe.codemother.entity.enums.GenerateTypeEnum;
import com.joe.codemother.exception.BusinessException;
import com.joe.codemother.exception.ErrorCode;
import org.apache.commons.lang3.StringUtils;

public class ParserExecutor {

    public static final HtmlCodeParser htmlCodeParser = new HtmlCodeParser();

    public static final MultiCodeParser multiCodeParser = new MultiCodeParser();

    public static Object parseCode(String content, GenerateTypeEnum generateTypeEnum) {
        if(StringUtils.isEmpty(content)) {
            return null;
        }
        if (generateTypeEnum == GenerateTypeEnum.HTML) {
            return htmlCodeParser.parseCode(content);
        }else if(generateTypeEnum == GenerateTypeEnum.MULTI_FILE){
            return multiCodeParser.parseCode(content);
        }else {
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"the requestType is not applied!");
        }
    }
}
